Passed
Pull Request — master (#101)
by Mathieu
02:08
created

User.getLastName   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import {Entity, Column, PrimaryGeneratedColumn, Index, OneToOne} from 'typeorm';
2
import {UserAdministrative} from './UserAdministrative.entity';
3
4
export enum UserRole {
5
  COOPERATOR = 'cooperator',
6
  EMPLOYEE = 'employee',
7
  ACCOUNTANT = 'accountant'
8
}
9
10
@Entity()
11
export class User {
12
  @PrimaryGeneratedColumn('uuid')
13
  private id: string;
14
15
  @Column({type: 'varchar', nullable: false})
16
  private firstName: string;
17
18
  @Column({type: 'varchar', nullable: false})
19
  private lastName: string;
20
21
  @Column({type: 'varchar', unique: true, nullable: false})
22
  private email: string;
23
24
  @Index('api-token')
25
  @Column({type: 'varchar', nullable: true})
26
  private apiToken: string;
27
28
  @Column({type: 'varchar', nullable: false})
29
  private password: string;
30
31
  @Column('enum', {enum: UserRole, nullable: false})
32
  private role: UserRole;
33
34
  @OneToOne(type => UserAdministrative, {nullable: true})
35
  private userAdministrative: UserAdministrative;
36
37
  @Column({type: 'timestamp', default: () => 'CURRENT_TIMESTAMP'})
38
  private createdAt: Date;
39
40
  constructor(
41
    firstName: string,
42
    lastName: string,
43
    email: string,
44
    apiToken: string,
45
    password: string,
46
    role: UserRole,
47
    userAdministrative?: UserAdministrative
48
  ) {
49
    this.firstName = firstName;
50
    this.lastName = lastName;
51
    this.email = email;
52
    this.apiToken = apiToken;
53
    this.password = password;
54
    this.role = role;
55
    this.userAdministrative = userAdministrative;
56
  }
57
58
  public getId(): string {
59
    return this.id;
60
  }
61
62
  public getFirstName(): string {
63
    return this.firstName;
64
  }
65
66
  public getLastName(): string {
67
    return this.lastName;
68
  }
69
70
  public getEmail(): string {
71
    return this.email;
72
  }
73
74
  public getApiToken(): string {
75
    return this.apiToken;
76
  }
77
78
  public getPassword(): string {
79
    return this.password;
80
  }
81
82
  public getRole(): UserRole {
83
    return this.role;
84
  }
85
86
  public getFullName(): string {
87
    return `${this.firstName} ${this.lastName}`;
88
  }
89
90
  public getUserAdministrative(): UserAdministrative {
91
    return this.userAdministrative;
92
  }
93
94
  public update(firstName: string, lastName: string, email: string): void {
95
    this.firstName = firstName;
96
    this.lastName = lastName;
97
    this.email = email;
98
  }
99
100
  public updatePassword(password: string): void {
101
    this.password = password;
102
  }
103
}
104